package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.CoinOperate;

public class CoinAcceptor
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public CoinAcceptor(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }
  
  public int coinReset()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.ResetCoin();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("硬币器复位:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinClearEvent()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.coinClearEvent();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("硬币器清空事件数:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinSelfCheck()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.SelfCheck();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("硬币器自检:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinTestSoleNoid()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.TestSoleNoid();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("测试磁铁:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinEnable()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.UseCoinPass();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("启用硬币通道:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinDisable()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.DisableCoinPass();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("禁用纸币器:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinPoll()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.coinPoll();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("接收硬币:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int coinEventCount()
  {
    int return_data = 0;
    try
    {
      if ("YL1".equals(this.deviceType))
      {
        CoinOperate.comNo = this.comNo;
        CoinOperate.baudRate = this.baudRate;
        
        return_data = CoinOperate.CheckEventCount();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("接收硬币:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
